package cn.ibobo.lease.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description 日期工具类
 * @Author lililiang
 * @Date 2018/12/14 19:11
 * @Param
 * @Return
 */
public class DateUtil {

	/**
	 * @Description 获取当前日期和时间
	 * @Author lililiang
	 * @Date 2018/12/14 19:12
	 * @Param []
	 * @Return java.lang.String
	 */
	public static String getNow(){
		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sd.format(new Date());
	}


	/**
	 * @Description 获取当前日期和时间后num秒的时间
	 * @Author lililiang
	 * @Date 2018/12/14 19:12
	 * @Param []
	 * @Return java.lang.String
	 */
	public static String getNextSecond(Integer num){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.add(Calendar.SECOND, num);
		SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sd.format(calendar.getTime());
	}

	/**
	 * @Description 计算参数时间到当前时间的小时数
	 * @Author lililiang
	 * @Date 2018/12/14 19:12
	 * @Param []
	 * @Return java.lang.String
	 */
	public static Integer getHour(String time){

        try {
            SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date start = sd.parse(time);
            Date end = new Date();
            long m = end.getTime() - start.getTime();
            if(m % (1000 * 60 * 60) == 0){
                return (int)(m/(1000 * 60 * 60));
            }else{
                return (int)(m/(1000 * 60 * 60) + 1);
            }
        } catch (ParseException e) {
            e.printStackTrace();
            return -1;
        }
	}

	public static void main(String[] args) {
		System.out.println(getNextSecond(10));
	}


}